﻿using Ardalis.Specification;
using Common.Utils;
using Domain.Entities;

namespace Application.Features.Roles.Specifications;

public class RoleAdvancedPaginationSpec : Specification<Role>
{
    public RoleAdvancedPaginationSpec(RoleAdvancedFilter filter)
    {
        Query.Where(q => q.RoleName!.Contains(filter.Keyword!) || q.Description!.Contains(filter.Keyword!), !string.IsNullOrWhiteSpace(filter.Keyword))
             .Where(x => x.RoleName == filter.RoleName, !filter.RoleName!.IsNullOrWhiteSpace())
             .Where(x => x.RoleCode == filter.RoleCode, !filter.RoleCode!.IsNullOrWhiteSpace())
             .Where(x => x.Description == filter.Description, !filter.Description!.IsNullOrWhiteSpace())
             .Where(x => x.IsActive == filter.IsActive, filter.IsActive.HasValue);
    }
}